﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MetaSharp.Transformation.Patterns
{
    class ClosurePattern : Pattern
    {
        public CallablePattern CallablePattern { get; private set; }
        public IImmutableArray<Pattern> Patterns { get; private set; }
        public ClosurePattern(CallablePattern callablePattern, IImmutableArray<Pattern> patterns)
            : base(PatternKind.Closure)
        {
            this.CallablePattern = callablePattern;
            this.Patterns = patterns;
        }

        public override PatternMatch Compile()
        {
            var p = CallablePattern
                .Pattern(Patterns)
                .Compile();

            return s => p(s);
        }
    }

    public class CallablePattern
    {
        public Func<IImmutableArray<Pattern>, Pattern> Pattern { get; private set; }

        public CallablePattern(Func<IImmutableArray<Pattern>, Pattern> pattern)
        {
            this.Pattern = pattern;
        }
    }
}
